package com.huabo.contract.service.impl;

import com.hbfk.util.PageInfo;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.oracle.entity.TblAttachment;
import com.huabo.contract.oracle.entity.TblLegalNegotiatedsettlemen;
import com.huabo.contract.oracle.mapper.TblLegalNegotiatedsettlemenMapper;
import com.huabo.contract.service.TblLegalNegotiatedsettlemenService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TblLegalNegotiatedsettlemenServiceImpl implements TblLegalNegotiatedsettlemenService {

    @Resource
    private TblLegalNegotiatedsettlemenMapper tblLegalNegotiatedsettlemenMapper;

    @Override
    public void findListByPage(PageInfo<TblLegalNegotiatedsettlemen> pageInfo, TblLegalNegotiatedsettlemen negotia, BigDecimal pid,Integer disputeid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalNegotiatedsettlemenMapper.findListByPage(pageInfo, negotia, pid, disputeid));
            pageInfo.setTotalRecord(tblLegalNegotiatedsettlemenMapper.findListByPageCount(negotia, pid, disputeid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalNegotiatedsettlemenMapper.findListByPage(pageInfo, negotia, pid, disputeid));
            pageInfo.setTotalRecord(tblLegalNegotiatedsettlemenMapper.findListByPageCount(negotia, pid, disputeid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        }
    }

    @Override
    public TblLegalNegotiatedsettlemen findById(Integer negotiaId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblLegalNegotiatedsettlemenMapper.findByNegotiaId(negotiaId);
        } else {
            return tblLegalNegotiatedsettlemenMapper.findByNegotiaId(negotiaId);
        }
    }

    @Override
    public void addDiputregistration(TblLegalNegotiatedsettlemen negotiated, String attids) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (attids != null && !"".equals(attids)) {
                List<TblAttachment> attList = new ArrayList(0);
                String[] attid = attids.split(",");
                TblAttachment att = null;
                String[] var6 = attid;
                int var7 = attid.length;

                for (int var8 = 0; var8 < var7; ++var8) {
                    String id = var6[var8];
                    att = new TblAttachment();
                    att.setAttid(new BigDecimal(id));
                    attList.add(att);
                }

                negotiated.setAttList(attList);
            }

            this.tblLegalNegotiatedsettlemenMapper.saveDiputregistration(negotiated);
        } else {
            if (attids != null && !"".equals(attids)) {
                List<TblAttachment> attList = new ArrayList(0);
                String[] attid = attids.split(",");
                TblAttachment att = null;
                String[] var6 = attid;
                int var7 = attid.length;

                for (int var8 = 0; var8 < var7; ++var8) {
                    String id = var6[var8];
                    att = new TblAttachment();
                    att.setAttid(new BigDecimal(id));
                    attList.add(att);
                }

                negotiated.setAttList(attList);
            }

            this.tblLegalNegotiatedsettlemenMapper.saveDiputregistration(negotiated);
        }
    }

    @Override
    public void removeLegalNegotiatedSettlemen(Integer negotiated) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblLegalNegotiatedsettlemenMapper.removeLegalNegotiatedSettlemen(negotiated);
        } else {
            tblLegalNegotiatedsettlemenMapper.removeLegalNegotiatedSettlemen(negotiated);
        }
    }

    @Override
    public void removeNegitiateRecord(Integer recordId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblLegalNegotiatedsettlemenMapper.removeNegitiateRecord(recordId);
        } else {
            tblLegalNegotiatedsettlemenMapper.removeNegitiateRecord(recordId);
        }
    }

    @Override
    public void modifyNegotiatedSettlement(TblLegalNegotiatedsettlemen oldNegotiated) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblLegalNegotiatedsettlemenMapper.updateOldNegotiated(oldNegotiated);
        } else {
            this.tblLegalNegotiatedsettlemenMapper.updateOldNegotiated(oldNegotiated);
        }
    }

    @Override
    public void findListForLitiationList(PageInfo<TblLegalNegotiatedsettlemen> pageInfo, TblLegalNegotiatedsettlemen negotiate) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalNegotiatedsettlemenMapper.findListForLitiationList(pageInfo, negotiate));
            pageInfo.setTotalRecord(tblLegalNegotiatedsettlemenMapper.findListForLitiationListCount(negotiate));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalNegotiatedsettlemenMapper.findListForLitiationList(pageInfo, negotiate));
            pageInfo.setTotalRecord(tblLegalNegotiatedsettlemenMapper.findListForLitiationListCount(negotiate));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        }
    }

//    @Override
//    public TblLegalNegotiatedsettlemen findNegotiaId(Integer negotiaId) {
//
//        return tblLegalNegotiatedsettlemenMapper.findNegotiaId(negotiaId);
//    }


}
